package ch.fhnw.qualiscan.core.libraries;

import java.io.Serializable;

import ch.fhnw.qualiscan.ApplicationData;

import com.vaadin.ui.Window;

import eu.livotov.tpt.TPTApplication;
/**
 * ModalLib provides functionality to add modal windows to the layout and also close them.
 * @author Kevin Mettenberger
 *
 */
@SuppressWarnings("serial")
public class ModalLibrary implements Serializable {
	
	public ModalLibrary() {}

	public void closeModal() {
		if( ((ApplicationData) TPTApplication.getCurrentApplication().getMainWindow().getData()).getCurrentModal() != null) {
			TPTApplication.getCurrentApplication().getMainWindow().removeWindow(((ApplicationData) TPTApplication.getCurrentApplication().getMainWindow().getData()).getCurrentModal());
			((ApplicationData) TPTApplication.getCurrentApplication().getMainWindow().getData()).setCurrentModal(null);
		} 
	}
	
	public void openModal(Window modal) {
		if(((ApplicationData) TPTApplication.getCurrentApplication().getMainWindow().getData()).getCurrentModal() == null) {
			((ApplicationData) TPTApplication.getCurrentApplication().getMainWindow().getData()).setCurrentModal(modal);
			TPTApplication.getCurrentApplication().getMainWindow().addWindow(modal);
		}
	}
	
}
